package com.liu.sx.service;

import com.liu.sx.common.util.IdWorker;
import com.liu.sx.dao.UserDao;
import com.liu.sx.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@Slf4j
@Transactional
public class UserService {

    @Autowired
    private IdWorker idWorker;

    @Autowired
    private UserDao userDao;

    @Autowired
    private BCryptPasswordEncoder cryptPasswordEncoder;


    public User login(String loginName, String password) {
      

          return null;
    }

    public void addUser(User user) {
        user.setId(idWorker.nextId()+"");
        user.setPassword(cryptPasswordEncoder.encode(user.getPassword()) );

        userDao.save(user);


    }

    public User findByName(String name) {
        return  userDao.findByName(name);


    }
}
